package com.ctshk.app.airexpress.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.airexpress.req.cache.CacheOpsReq;
import com.ctshk.rpc.airexpress.req.cache.CacheSetReq;
import com.ctshk.rpc.airexpress.service.IAirportExpressAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "机场快线缓存管理", tags = "机场快线缓存管理")
@RestController
@RequestMapping("/airport/express/cache")
public class AirportExpressCacheController extends BaseController {

    @DubboReference
    private IAirportExpressAppService airportExpressAppService;

    @ApiOperation(value = "机场快线-缓存-初始化", notes = "机场快线-缓存-初始化")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "机场快线-缓存-初始化", operDesc = "机场快线-缓存-初始化")
    @PostMapping("/home/init")
    public Result cacheInit(@RequestBody List<Long> channelIds) {
        return airportExpressAppService.cacheInit(channelIds);
    }

    @ApiOperation(value = "机场快线-缓存-更新", notes = "机场快线-缓存-更新")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-缓存-更新", operDesc = "机场快线-缓存-更新")
    @PostMapping("/home/update")
    public Result cacheUpdate(@RequestBody CacheOpsReq cacheOpsReq) {
        return airportExpressAppService.cacheUpdate(cacheOpsReq);
    }

    @ApiOperation(value = "机场快线-缓存-删除", notes = "机场快线-缓存-删除")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.DELETE, operTitle = "机场快线-缓存-删除", operDesc = "机场快线-缓存-删除")
    @PostMapping("/home/delete")
    public Result cacheDelete(@RequestBody CacheOpsReq cacheOpsReq) {
        return airportExpressAppService.cacheDelete(cacheOpsReq);
    }

    @ApiOperation(value = "机场快线-缓存-剩余票数操作", notes = "机场快线-缓存-剩余票数操作")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-缓存-剩余票数操作", operDesc = "机场快线-缓存-剩余票数操作")
    @PostMapping("/remain/update")
    public Result remainderNumberUpdate(@RequestBody CacheSetReq req) {
        return airportExpressAppService.remainderNumberCacheOps(req);
    }

    @ApiOperation(value = "机场快线-缓存-更新(测试)", notes = "机场快线-缓存-更新(测试)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-缓存-更新", operDesc = "机场快线-缓存-更新")
    @GetMapping("/test")
    public Result cacheTest() {
        return airportExpressAppService.buildCacheData(null, null);
    }
}